home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13850 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  41 lines

  1. Path: eccdb1.pms.ford.com!pms991!mbobak
  2. From: mbobak@pms991.uucp (Mark J. Bobak)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: reversing a string
  5. Date: 10 Apr 1996 14:38:40 GMT
  6. Organization: Not an Official Spokesperson for Ford Motor Company, Dearborn, MI
  7. Message-ID: <4kgh5g$1ue@eccdb1.pms.ford.com>
  8. References: <4k6cjl$j8f@central.server.swt.edu>
  9. NNTP-Posting-Host: pms991.pms.ford.com
  10.  
  11. In article <4k6cjl$j8f@central.server.swt.edu>,
  12. Leland Newsom <ln16674@nyssa.swt.edu> wrote:
  13. >I have a challenge from a friend of mine.  He wanted me to reverse a string 
  14. >with recursion without using any additional variables or loops.  I got mine
  15. >to work by using exclusive or, but I needed an additional variable.  Can 
  16. >someone help with this problem without using the additional variable?
  17. >
  18. >Thanks
  19.  
  20.  
  21. Well, here's what I came up with....it seems to work.
  22.  
  23. #include <stdio.h>
  24. #include <string.h>
  25. void revstr(char *string, int position)
  26. {
  27.     printf("%c",string[position]);
  28.     if(position-1 >= 0)
  29.         revstr(string,position-1);
  30. }
  31. main(int argc, char **argv)
  32. {
  33.     revstr(argv[1],strlen(argv[1]));
  34.     printf("\n");
  35. }
  36. -- 
  37. Mark J. Bobak, Application Developer
  38. Advanced Vehicle & Computer Aided Engineering Systems Department
  39. Process Leadership, Ford Motor Company
  40. mbobak@ford.com
  41.